#include <glib.h>

static void my_log_handler(const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer user_data)
{
    g_print("[%s]my_log_handler : %s \n",user_data,message);

}
gint main(gint argc, gchar **argv)
{
    guint handler_id = 0;

    //g_log_set_handler(NULL, G_LOG_LEVEL_DEBUG|G_LOG_LEVEL_INFO|G_LOG_LEVEL_WARNING|G_LOG_FLAG_FATAL|G_LOG_FLAG_RECURSION, my_log_handler, "APP_TAG");
    g_print("set handler: G_LOG_LEVEL_MASK|G_LOG_FLAG_FATAL|G_LOG_FLAG_RECURSION \n");
    handler_id = g_log_set_handler(NULL, 
        G_LOG_LEVEL_MASK|G_LOG_FLAG_FATAL|G_LOG_FLAG_RECURSION, my_log_handler, "APP_TAG");

    g_debug("debug");
    g_info("info");
    g_message("message");
    g_warning("warning");
    g_critical("critical");
    //g_error("error");

    g_log_remove_handler(NULL, handler_id);

    g_print("set handler: G_LOG_LEVEL_INFO|G_LOG_FLAG_FATAL|G_LOG_FLAG_RECURSION \n");

    handler_id = g_log_set_handler(NULL, 
        G_LOG_LEVEL_INFO|G_LOG_FLAG_FATAL|G_LOG_FLAG_RECURSION, my_log_handler, "APP_TAG");
    g_debug("debug");
    g_info("info");
    g_message("message");
    g_warning("warning");
    g_critical("critical");

    g_log_remove_handler(NULL, handler_id);

    g_print("set handler: G_LOG_LEVEL_INFO|G_LOG_LEVEL_WARNING|G_LOG_FLAG_FATAL|G_LOG_FLAG_RECURSION \n");
    handler_id = g_log_set_handler(NULL, 
        G_LOG_LEVEL_INFO|G_LOG_LEVEL_WARNING|G_LOG_FLAG_FATAL|G_LOG_FLAG_RECURSION, my_log_handler, "APP_TAG");

    g_debug("debug");
    g_info("info");
    g_message("message");
    g_warning("warning");
    g_critical("critical");

    
    g_log_remove_handler(NULL, handler_id);

    g_print("set handler: G_LOG_LEVEL_MASK|G_LOG_FLAG_FATAL|G_LOG_FLAG_RECURSION \n");
    handler_id = g_log_set_handler(NULL, 
        G_LOG_LEVEL_MASK|G_LOG_FLAG_FATAL|G_LOG_FLAG_RECURSION, my_log_handler, "APP_TAG");

    g_log_set_always_fatal(G_LOG_LEVEL_MESSAGE);
    g_debug("debug");
    g_info("info");
    g_message("message");
    g_warning("warning");
    g_critical("critical");

    return 0;
}

